home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
007
/
simcode.arc
/
DIREAD.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1985-01-19
|
4KB
|
121 lines
{$symtab-,$pagesize:84,$linesize:96,$debug-,
$title:'DIREAD.PAS -- read and display a directory'}
{ COPYRIGHT @ 1984
Jim & Eric Holtman
35 Dogwood Trail
Randolph, NJ 07869
(201) 361-3395
}
module diread;
function dosxqq(comm, parm : word): byte;
external;
procedure putchar(inchar : char);
external;
procedure print_dir;
type
symtabptr = ^symtab;
symtab = record
sym_name : string(13);
sym_next : symtabptr;
end;
dta_type = record
reserved : string(20);
attribute : byte;
time : word;
date : word;
size : array[0..1] of integer;
name : string(13);
end;
var
crcxqq [external]: word;
dta : dta_type;
fs: lstring(100);
i,j,q : integer;
err : byte;
top,lptr,nptr : symtabptr;
procedure cleanup; {delete all entries on the chain}
begin
lptr := top;
repeat
nptr := lptr^.sym_next;
dispose(lptr);
lptr := nptr;
until lptr = nil;
end;
begin
new(top);
top^.sym_name := chr(0)*' ';
{low}
new(top^.sym_next);
top^.sym_next^.sym_name := chr(#FF)*' ';
{high}
top^.sym_next^.sym_next := nil;
write('Directory/Pattern (full path): ');
readln(fs);
if fs = '\' then fs := null;
if (positn('*',fs,1)>0) or (positn('?',fs,1)>0) then concat(fs,chr(0))
else concat(fs,'\*.*'*chr(0));
eval(dosxqq(#1A,wrd(adr dta)));
crcxqq := 0;
err := dosxqq(#4E, wrd(adr fs) + 1);
if err=3 then begin
writeln('Path not found');
cleanup;
return;
end;
putchar(chr(10));
putchar(chr(13));
while err <> 18 do begin
j := scaneq(13,chr(0),dta.name,1);
{find the end of the string}
for q := j+1 to 13 do dta.name[q] := ' ';
{pad with blanks}
lptr := top; {search the list for a place to put the name}
nptr := lptr^.sym_next;
while nptr <> nil do begin
if nptr^.sym_name > dta.name then begin
{location found}
new(nptr); {allocate the block}
nptr^.sym_name := dta.name;
{init the variables}
nptr^.sym_next := lptr^.sym_next;
{insert into chain}
lptr^.sym_next := nptr;
nptr := nil;
end
else begin
lptr := nptr;
nptr := nptr^.sym_next;
end;
end;
err := dosxqq(#4F,0); {next matching entry}
end;
i := 0;
nptr := top^.sym_next; {print out the sorted files}
while nptr <> nil do begin
for j := 1 to 13 do putchar(nptr^.sym_name[j]);
i := i+1;
if (i mod 6) = 0 then begin
putchar(chr(10));
putchar(chr(13));
end;
nptr := nptr^.sym_next;
end;
putchar(chr(10));
putchar(chr(13));
cleanup;
end; end.